require(['./config'], () => {
  require(['jquery'], () => {
    class Login {
      constructor () {
        this.LoadHTML()
        this.regBtn()
        this.logBtn()
      }

      LoadHTML () {
        console.log(location.search)
        if (location.search.slice(1) === "regis") {
          $('#reg-log').attr('checked', true);
        }
        
      }

      regBtn () {
        $('.regbtn').on('click', (e) => {
          e.preventDefault()
          const name = $('#regname').val()
          const pwd = $('#regpass').val()
          $.ajax({
            method: 'POST',
            url: 'http://www.hehui.com/api/regis.php',
            data: { name, pwd},
            dataType: 'json',
            success: function (resp) {
              if (resp.code == 200) {
                alert(resp.body.msg)
                $('#reg-log').attr('checked', false);
              }
            }
          })
        })
      }
      logBtn () {
        $('.logbtn').on('click', (e) => {
          e.preventDefault()
          const name = $('#logname').val()
          const pwd = $('#logpass').val()
          $.ajax({
            method: 'POST',
            url: 'http://www.hehui.com/api/login.php',
            data: { name, pwd},
            dataType: 'json',
            success: function (resp) {
              if (resp.code == 200) {
                alert(resp.body.msg)
                document.cookie= `name=${name}; path=/`
                location.assign('/?0')
              } else {
                alert(resp.body.msg)
              }
            }
          })
        })
      }
    }
    new Login()
  })
})